package com.bishe.controller.utils;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class ky implements Filter {
    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
            throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;
        HttpServletRequest request = (HttpServletRequest) req;
        response.setHeader("Access-Control-Allow-Origin", "*"); // 设置允许跨域的源
        response.setHeader("Access-Control-Allow-Methods", "*"); // 设置允许的请求方法
        response.setHeader("Access-Control-Allow-Headers", "*"); // 设置允许的请求头
        response.setHeader("Access-Control-Max-Age", "3600"); // 设置缓存时间
        chain.doFilter(req, res);
    }
}